package com.white.databasesbackup.entity;


import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.List;

@Data
@NoArgsConstructor
public class PageVO<T> {
    private static final long serialVersionUID = -4715445356538886583L;

    /**
     * 每页条数
     */
    private Integer size = 10;

    /**
     * 当前页
     */
    private Integer page = 1;

    /**
     * 分页数据
     */
    private List<T> data = Collections.emptyList();

    /**
     * 总条数
     */
    private Integer total = 0;

    /**
     * 总页数
     */
    private Integer totalPage = 0;


    public PageVO(Integer page, Integer size) {
        this.page = page;
        this.size = size;
    }

    public PageVO(Integer page, Integer size, Integer total, List<T> data) {
        this.page = page;
        this.size = size;
        this.data = data;
        this.total = total;
        this.totalPage = (total + size - 1) / size;
    }

    /**
     * 空数据
     */
    public static <T> PageVO<T> emptyPage(Integer page, Integer size) {
        return new PageVO<>(page, size);
    }

    /**
     * 填充数据
     */
    public static <T> PageVO<T> fullPage(Integer page, Integer size, int count, List<T> data) {
        return new PageVO<>(page, size, count, data);
    }
}
